<xsl:stylesheet
  version="1.0"
  exclude-result-prefixes="x d xsl msxsl cmswrt"
  xmlns:x="http://www.w3.org/2001/XMLSchema"
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
  xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

	<xsl:template name="Default" match="*" mode="itemstyle">
		Please select a specific template.
	</xsl:template>

	<xsl:template name="AmGridviewItem" match="Row[@Style='AmGridviewItem']" mode="itemstyle">
		<xsl:variable name="Image">
			<xsl:choose>
				<xsl:when test="string-length(@PodcastThumbnail)=0">
					<xsl:value-of select="string('/Style Library/PodcastingKit/Images/NoVideo.jpg')" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="substring-before(@PodcastThumbnail, ',')" />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="Title">
			<xsl:value-of select="@Title" />
		</xsl:variable>
    <xsl:variable name="AuthorID">
      <xsl:value-of select="substring-before(@PodcastAuthor, ';')"/>
    </xsl:variable>
		<xsl:variable name="SafeLinkUrl">
      <xsl:value-of select="concat('/Pages/PodcastDetail.aspx?itemId=', @ID, '&amp;userId=', $AuthorID, '&amp;csId=%7B', @WebId, '%7D%40%7B', @ListId, '%7D')"/>
		</xsl:variable>
		<xsl:variable name="Desc">
			<xsl:variable name="Desc1">
				<xsl:call-template name="OuterTemplate.Replace">
					<xsl:with-param name="Value" select="@Description"/>
					<xsl:with-param name="Search" select="string('&lt;div&gt;')"/>
					<xsl:with-param name="Replace" select="string('')"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:call-template name="OuterTemplate.Replace">
				<xsl:with-param name="Value" select="$Desc1"/>
				<xsl:with-param name="Search" select="string('&lt;/div&gt;')"/>
				<xsl:with-param name="Replace" select="string('')"/>
			</xsl:call-template>
		</xsl:variable>

		<div>
			<a href="{$SafeLinkUrl}">
				<img src="{$Image}" width="120px" height="90px" alt="{$Desc}" />
			</a>
		</div>
		<div class="am-griditem-desc" style="height:40px;overflow:hidden;">
      <table>
				<tr>
					<td valign="middle" height="40px">
						<a class="am-desclink">
							<xsl:attribute name="href">
								<xsl:choose>
									<xsl:when test="contains(@FileURL, '&amp;action=view')">
										<xsl:value-of select="concat(substring-before(@FileURL, '&amp;action=view'), '&amp;action=download')"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="@FileURL"/>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:attribute>
							<xsl:choose>
								<xsl:when test="string-length($Title) > 50">
									<xsl:value-of select="substring($Title, 1, 47)" />
									<xsl:value-of select="'...'" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$Title" />
								</xsl:otherwise>
							</xsl:choose>
						</a>
					</td>
				</tr>
			</table>
		</div>
		<div>
      <!--Rating-->
      <xsl:variable name="rate" select="substring-before(@Rating, ',')" />
      <xsl:choose>
        <xsl:when test="string-length(@Rating)=0 or $rate&lt;=0">
          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
        </xsl:when>
        <xsl:otherwise>
          <!-- 1 -->
          <xsl:choose>
            <xsl:when test ="$rate &gt;= 1">
              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
            </xsl:when>
            <xsl:otherwise>
              <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
            </xsl:otherwise>
          </xsl:choose>
          <!-- 2 -->
          <xsl:choose>
            <xsl:when test ="$rate &gt;= 2">
              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$rate &gt; 1">
                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
                </xsl:when>
                <xsl:otherwise>
                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
          <!-- 3 -->
          <xsl:choose>
            <xsl:when test ="$rate &gt;= 3">
              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$rate &gt; 2">
                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
                </xsl:when>
                <xsl:otherwise>
                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
          <!-- 4 -->
          <xsl:choose>
            <xsl:when test ="$rate &gt;= 4">
              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$rate &gt; 3">
                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
                </xsl:when>
                <xsl:otherwise>
                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
          <!-- 5 -->
          <xsl:choose>
            <xsl:when test ="$rate &gt;= 5">
              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$rate &gt; 4">
                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
                </xsl:when>
                <xsl:otherwise>
                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>

           <!--<xsl:value-of select="$rate"/>/<xsl:value-of select="substring-after(@Rating, ',')"/>-->
        </xsl:otherwise>
      </xsl:choose>
      <!--End Rating-->
		</div>
		<div class="am-griditem-user">
			<table height="30px">
				<tr>
					<td valign="top" width="40px">
						<xsl:value-of select="string('By ')" />
					</td>
					<td valign="top" style="font-size:10px;">
						<xsl:call-template name="OuterTemplate.GetSafeUserLink">
							<xsl:with-param name="SharePointUser" select="@PodcastAuthor" />
						</xsl:call-template>
					</td>
				</tr>
			</table>
		</div>
		<div>
			<div>
				<xsl:value-of select="@Format" /> (<xsl:value-of select="@PodcastLanguage"/>)
			</div>
			<div>
				<xsl:value-of select="string('Pub: ')" />
				<xsl:call-template name="OuterTemplate.FormatDate">
					<xsl:with-param name="DateTime" select="@PodcastPublishDate" />
				</xsl:call-template>
			</div>
			<div>
        <xsl:value-of select="@PodcastDuration" /> (<xsl:value-of select="@PodcastSize" />)
			</div>
		</div>
		<div>
			<table width="100%">
				<tr>
					<!-- <td style="width:33%;text-align:left">
						<input type="checkbox" />
						<img src="/_layouts/images/blank.gif" border="0" alt="" />
					</td> -->
					<td style="width:50%;text-align:left">
						<img src="/Style Library/PodcastingKit/Images/thumb_68.gif" />
						<xsl:value-of select="round(@Downloads)" />
					</td>
					<td style="width:50%;text-align:right">
						<img src="/Style Library/PodcastingKit/Images/thumb_70.gif" />
						<xsl:choose>
							<xsl:when test="string-length(@Rating)=0">
								0
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="substring-after(@Rating,',')"/>
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</tr>
			</table>
		</div>

	</xsl:template>
	
	<xsl:template name="PsmsMobileItem" match="Row[@Style='PsmsMobileItem']" mode="itemstyle">
		<xsl:variable name="Image">
			<xsl:choose>
				<xsl:when test="string-length(@PodcastThumbnail)=0">
					<xsl:value-of select="string('/Style Library/PodcastingKit/Images/NoVideo.jpg')" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="substring-before(@PodcastThumbnail, ',')" />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="Title">
			<xsl:value-of select="@Title" />
		</xsl:variable>
    <xsl:variable name="AuthorID">
      <xsl:value-of select="substring-before(@PodcastAuthor, ';')"/>
    </xsl:variable>
		<xsl:variable name="SafeLinkUrl">
			<xsl:value-of select="@FileURL"/>
			<!--<xsl:value-of select="concat('/Pages/PodcastDetail.aspx?itemId=', @ID, '&amp;userId=', $AuthorID, '&amp;csId=%7B', @WebId, '%7D%40%7B', @ListId, '%7D')"/>-->
		</xsl:variable>
		
		<table width="320px">
			<tr>
				<td width="120px" valign="top" style="padding-right:6px;">
					<div>
						<a href="{$SafeLinkUrl}">
							<img src="{$Image}" width="120px" height="90px" alt="" border="0" />
						</a>
					</div>
					<div>
						<a class="am-desclink" href="{$SafeLinkUrl}">
							<xsl:choose>
								<xsl:when test="string-length($Title) > 50">
									<xsl:value-of select="substring($Title, 1, 47)" />
									<xsl:value-of select="'...'" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$Title" />
								</xsl:otherwise>
							</xsl:choose>
						</a>
					</div>
					<div style="padding-top:6px;padding-bottom:6px;">
				      <!--Rating-->
				      <xsl:variable name="rate" select="substring-before(@Rating, ',')" />
				      <xsl:choose>
				        <xsl:when test="string-length(@Rating)=0 or $rate&lt;=0">
				          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
				          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
				          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
				          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
				          <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: 0" />
				        </xsl:when>
				        <xsl:otherwise>
				          <!-- 1 -->
				          <xsl:choose>
				            <xsl:when test ="$rate &gt;= 1">
				              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:when>
				            <xsl:otherwise>
				              <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:otherwise>
				          </xsl:choose>
				          <!-- 2 -->
				          <xsl:choose>
				            <xsl:when test ="$rate &gt;= 2">
				              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:when>
				            <xsl:otherwise>
				              <xsl:choose>
				                <xsl:when test="$rate &gt; 1">
				                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:when>
				                <xsl:otherwise>
				                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:otherwise>
				              </xsl:choose>
				            </xsl:otherwise>
				          </xsl:choose>
				          <!-- 3 -->
				          <xsl:choose>
				            <xsl:when test ="$rate &gt;= 3">
				              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:when>
				            <xsl:otherwise>
				              <xsl:choose>
				                <xsl:when test="$rate &gt; 2">
				                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:when>
				                <xsl:otherwise>
				                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:otherwise>
				              </xsl:choose>
				            </xsl:otherwise>
				          </xsl:choose>
				          <!-- 4 -->
				          <xsl:choose>
				            <xsl:when test ="$rate &gt;= 4">
				              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:when>
				            <xsl:otherwise>
				              <xsl:choose>
				                <xsl:when test="$rate &gt; 3">
				                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:when>
				                <xsl:otherwise>
				                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:otherwise>
				              </xsl:choose>
				            </xsl:otherwise>
				          </xsl:choose>
				          <!-- 5 -->
				          <xsl:choose>
				            <xsl:when test ="$rate &gt;= 5">
				              <img src="/Style Library/PodcastingKit/Images/star_yellow.gif" alt="Avg. Rating: {$rate}" />
				            </xsl:when>
				            <xsl:otherwise>
				              <xsl:choose>
				                <xsl:when test="$rate &gt; 4">
				                  <img src="/Style Library/PodcastingKit/Images/star_half.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:when>
				                <xsl:otherwise>
				                  <img src="/Style Library/PodcastingKit/Images/star_gray.gif" alt="Avg. Rating: {$rate}" />
				                </xsl:otherwise>
				              </xsl:choose>
				            </xsl:otherwise>
				          </xsl:choose>
				        </xsl:otherwise>
				      </xsl:choose>
				      <!--End Rating-->
						</div>
						<div class="am-griditem-user">
							<table height="30px">
								<tr>
									<td valign="top" width="40px">
										<xsl:value-of select="string('By ')" />
									</td>
									<td valign="top" style="font-size:10px;">
										<xsl:choose>
									      <xsl:when test="contains(@PodcastAuthor, '\')">
									        <xsl:value-of select="substring-after(@PodcastAuthor, '\')" />
									      </xsl:when>
									      <xsl:otherwise>
									        <xsl:value-of select="substring-after(@PodcastAuthor, '#')" />
									      </xsl:otherwise>
									    </xsl:choose>
									</td>
								</tr>
							</table>
						</div>
						<div>
							<div>
								<xsl:value-of select="@Format" /> (<xsl:value-of select="@PodcastLanguage"/>)
							</div>
							<div>
								<xsl:value-of select="string('Pub: ')" />
								<xsl:call-template name="OuterTemplate.FormatDate">
									<xsl:with-param name="DateTime" select="@PodcastPublishDate" />
								</xsl:call-template>
							</div>
							<div>
				        <xsl:choose>
				          <xsl:when test="string-length(@PodcastDuration)=0">
				            Unknown Duration
				          </xsl:when>
				          <xsl:otherwise>
				            <xsl:value-of select="@PodcastDuration" />
				          </xsl:otherwise>
				        </xsl:choose>
							</div>
						</div>
						<div>
							<table width="50%">
								<tr>
									<td style="width:33%;text-align:left">
										<img src="/Style Library/PodcastingKit/Images/thumb_68.gif" />0
									</td>
									<td style="width:33%;text-align:left">
										<img src="/Style Library/PodcastingKit/Images/thumb_70.gif" />
										<xsl:choose>
											<xsl:when test="string-length(@Rating)=0">
												0
											</xsl:when>
											<xsl:otherwise>
												<xsl:value-of select="substring-after(@Rating,',')"/>
											</xsl:otherwise>
										</xsl:choose>
									</td>
								</tr>
							</table>
						</div>
				</td>
				<td valign="top">
					<xsl:value-of select="@Description" disable-output-escaping="yes" />
				</td>
			</tr>
		</table>
		
		

	</xsl:template>

</xsl:stylesheet>
